package cc.bookcloud.tool.ocr.common;


import lombok.Data;

import java.io.Serializable;

@Data
public class JResult<T> implements Serializable {


    public static final int _Err_COMMON_CODE = 444;
    // 错误代码，默认0-未出错
    private int code = 0;
    // 错误消息，默认success-成功
    private String msg = "操作成功";
    // 目录对象
    private T data;

    // 总执行时间
    private Long totalTime;


    private JResult() {
    }

    public JResult ok(T data) {
        this.data = data;
        return this;
    }

    public JResult ok(T data, String msg) {
        this.data = data;
        this.msg = msg;
        return this;
    }


    public JResult failed(String msg) {
        this.code = _Err_COMMON_CODE;
        this.msg = msg;
        return this;
    }

    public JResult failed(int code, String msg) {
        this.code = code;
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static JResult build() {
        JResult wResult = null;
        try {
            wResult = (JResult) prototype.clone();

        } catch (CloneNotSupportedException e) {
            wResult = new JResult();
        }
        return wResult;
    }

    protected final static JResult prototype = new JResult();


}
